<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="description" content="">
  <meta name="keywords" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>article with sidebar  | Amaze UI Examples</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp"/>
  <link rel="icon" type="image/png" href="assets/i/favicon.png">
  <meta name="mobile-web-app-capable" content="yes">
  <link rel="icon" sizes="192x192" href="assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
  <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
  <meta name="msapplication-TileImage" content="assets/i/app-icon72x72@2x.png">
  <meta name="msapplication-TileColor" content="#0e90d2">
  <link rel="stylesheet" href="assets/css/amazeui.min.css">
  <link rel="stylesheet" href="assets/css/app.css">

    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
    <script src="assets/js/amazeui.ie8polyfill.min.js"></script>
    <script src="assets/js/layui.js" charset="utf-8" type="text/javascript"></script>
    <script src="assets/js/amazeui.min.js"></script>
    <script src="assets/js/common.js"></script>
</head>

<body id="blog-article-sidebar">
<!-- header start -->
<header class="am-g am-g-fixed blog-fixed blog-text-center blog-header">
    <div class="am-u-sm-8 am-u-sm-centered">
        <img width="200" src="http://s.amazeui.org/media/i/brand/amazeui-b.png" alt="Amaze UI Logo"/>
        <h2 class="am-hide-sm-only">中国首个开源 HTML5 跨屏前端框架</h2>
    </div>
</header>
<!-- header end -->
<hr>

<!-- nav start -->
<nav class="am-g am-g-fixed blog-fixed blog-nav">
<button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only blog-button" data-am-collapse="{target: '#blog-collapse'}" ><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

  <div class="am-collapse am-topbar-collapse" id="blog-collapse">
    <ul class="am-nav am-nav-pills am-topbar-nav">
      <li class="am-active"><a href="lw-index.html">首页</a></li>
      <li class="am-dropdown" data-am-dropdown>
        <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
          首页布局 <span class="am-icon-caret-down"></span>
        </a>
        <ul class="am-dropdown-content">
          <li><a href="lw-index.html">1. blog-index-standard</a></li>
          <li><a href="lw-index-nosidebar.html">2. blog-index-nosidebar</a></li>
          <li><a href="lw-index-center.html">3. blog-index-layout</a></li>
          <li><a href="lw-index-noslider.html">4. blog-index-noslider</a></li>
        </ul>
      </li>
      <li><a href="lw-article.html">标准文章</a></li>
      <li><a href="lw-img.html">图片库</a></li>
      <li><a href="lw-article-fullwidth.html">全宽页面</a></li>
      <li><a href="lw-timeline.html">存档</a></li>
    </ul>
    <form class="am-topbar-form am-topbar-right am-form-inline" role="search">
      <div class="am-form-group">
        <input type="text" class="am-form-field am-input-sm" placeholder="搜索">
      </div>
    </form>
  </div>
</nav>
<!-- nav end -->
<hr>
<!-- content srart -->
<div class="am-g am-g-fixed blog-fixed blog-content">
    <div class="am-u-md-8 am-u-sm-12">
      <article class="am-article blog-article-p">
        <div class="am-article-hd">
          <h1 class="am-article-title blog-text-center" id="title">我的文章哎</h1>
            <p class="am-article-meta blog-text-center">
                <span id="createdAt">2019年1月11号</span>
            </p>
          <p class="am-article-meta blog-text-center">
              <span >字数 <span id="word">422</span></span>-
              <span >喜欢数 <span id="like">422</span></span>-
              <span >评论数 <span id="comment">422</span></span>
          </p>
            <p id="content">
                大家提到程序员第一时间想到的是什么，我想你脑袋里的第一印象就是：一身材消瘦的毕业生戴着眼镜坐在电脑前飞快的敲着代码，满脸痘痘，聚精会神。程序员是一个很费脑的行业，因为经常对着电脑，平时经常加班，所以很多人中年就谢顶了，主要还是互联网行业加班实在太严重，几乎个人时间都没有。
            </p>
        </div>
      </article>

        <hr>

        <form class="am-form am-g">
            <h3 class="blog-comment">评论</h3>
          <fieldset>
            <div class="am-form-group">
              <textarea id="commentText" class="" rows="5" placeholder="一字千金"></textarea>
            </div>

            <p><button type="button" class="am-btn am-btn-default" onclick="pushComment()">发表评论</button></p>
          </fieldset>
        </form>

        <hr>
        <div id = "comments">
            <article class='am-g blog-entry-article'>
                <div class='am-u-lg-6 am-u-md-12 am-u-sm-12 topic-entry-img'>
                    <img src='assets/i/f10.jpg' alt='' class='user-img'>
                </div>
                <div class='am-u-lg-6 am-u-md-12 am-u-sm-12 blog-entry-text'>
                    <span><a href='' class='comment-name'>作者 &nbsp;</a></span>
                    <span class="comment-time">2018年12月1日</span>
                    <p class="comment-text">呵呵呵呵</p>
                    <p></p>
                </div>
            </article>
        </div>
    </div>

    <div class="am-u-md-4 am-u-sm-12 blog-sidebar">
        <div class="blog-sidebar-widget blog-bor">
            <h2 class="blog-text-center blog-title"><span>About ME</span></h2>
            <img id="img" src="assets/i/f161.jpg" alt="about me" class="user-img2" >

            <p><a href='lw-user.html?userId=' class='user-name' id="username">作者 &nbsp;</a></p>
            <p class="topic-entry-tiny-text"><span id="articles">234</span>篇文章 &nbsp;&nbsp; <span id="followers">2344</span>人关注</p>
            <hr>
            <p id="introduction">我不想成为一个庸俗的人。十年百年后，当我们死去，质疑我们的人同样死去，后人看到的是裹足不前、原地打转的你，还是一直奔跑、走到远方的我？</p>
        </div>

    </div>
</div>
<!-- content end -->


 <footer class="blog-footer">
    <div class="am-g am-g-fixed blog-fixed am-u-sm-centered blog-footer-padding">
        <div class="am-u-sm-12 am-u-md-4- am-u-lg-4">
            <h3>模板简介</h3>
            <p class="am-text-sm">这是一个使用amazeUI做的简单的前端模板。<br> 博客/ 资讯类 前端模板 <br> 支持响应式，多种布局，包括主页、文章页、媒体页、分类页等<br>嗯嗯嗯，不知道说啥了。外面的世界真精彩<br><br>
            Amaze UI 使用 MIT 许可证发布，用户可以自由使用、复制、修改、合并、出版发行、散布、再授权及贩售 Amaze UI 及其副本。</p>
        </div>
        <div class="am-u-sm-12 am-u-md-4- am-u-lg-4">
            <h3>社交账号</h3>
            <p>
                <a href=""><span class="am-icon-qq am-icon-fw am-primary blog-icon blog-icon"></span></a>
                <a href=""><span class="am-icon-github am-icon-fw blog-icon blog-icon"></span></a>
                <a href=""><span class="am-icon-weibo am-icon-fw blog-icon blog-icon"></span></a>
                <a href=""><span class="am-icon-reddit am-icon-fw blog-icon blog-icon"></span></a>
                <a href=""><span class="am-icon-weixin am-icon-fw blog-icon blog-icon"></span></a>
            </p>
            <h3>Credits</h3>
            <p>我们追求卓越，然时间、经验、能力有限。Amaze UI 有很多不足的地方，希望大家包容、不吝赐教，给我们提意见、建议。感谢你们！</p>
        </div>
        <div class="am-u-sm-12 am-u-md-4- am-u-lg-4">
              <h1>我们站在巨人的肩膀上</h1>
             <h3>Heroes</h3>
            <p>
                <ul>
                    <li>jQuery</li>
                    <li>Zepto.js</li>
                    <li>Seajs</li>
                    <li>LESS</li>
                    <li>...</li>
                </ul>
            </p>
        </div>
    </div>
    <div class="blog-text-center">© 2015 AllMobilize, Inc. Licensed under MIT license. Made with love By LWXYFER</div>
  </footer>

<script>
    var articleId = window.location.href.split("=")[1]
    var userId
    var layer;
    layui.use(['layer', 'form'], function(){
        layer = layui.layer
            ,form = layui.form;
    });
    $(document).ready(
        function(){
            $.ajax({
                type: 'POST',
                url: 'http://localhost:8764/pcApi/article/'+ articleId,
                dataType: 'json',
                contentType: "application/json",
                success: function (data) {

                    $("#title").html(data.title);
                    $("#createdAt").html(format(data.createdAt));
                    $("#word").html(data.articleData.word);
                    $("#like").html(data.articleData.like);
                    $("#comment").html(data.articleData.comment);
                    $("#content").html(data.content);

                    userId = data.user.id
                    getUser(userId);
                    console.log(data)
                },
                error: function (XMLHttpRequest, textStatus, errorThown) {
                    alert("操作失败！");
                }
            });
            getComment();
        }
    )

    //获取评论
    function getComment() {
        $.ajax({
            type: 'POST',
            url: 'http://localhost:8764/pcApi/comment/index/'+ articleId,
            dataType: 'json',
            contentType: "application/json",
            success: function (data) {
                var list = data.data
                var html = ""
                for(i = 0;i < list.length;i++){
                    html += "<article class='am-g blog-entry-article'>\n" +
                        "                <div class='am-u-lg-6 am-u-md-12 am-u-sm-12 topic-entry-img'>\n" +
                        "                    <img src='" + list[i].user.idPhoto +"' alt='' class='user-img'>\n" +
                        "                </div>\n" +
                        "                <div class='am-u-lg-6 am-u-md-12 am-u-sm-12 blog-entry-text'>\n" +
                        "                    <span><a href='lw-user.html?userId=" + list[i].user.id + "' class='comment-name'>" + list[i].user.username + "&nbsp;</a></span>\n" +
                        "                    <span class=\"comment-time\">" + format(list[i].createdAt) +"</span>\n" +
                        "                    <p class=\"comment-text\">" + list[i].text +"</p>\n" +
                        "                    <p></p>\n" +
                        "                </div>\n" +
                        "            </article>"
                }

                $("#comments").html(html)
                console.log(data)
            },
            error: function (XMLHttpRequest, textStatus, errorThown) {
                alert("操作失败！");
            }
        });
    }
    //获取用户信息
    function getUser(userId) {
        $.ajax({
            type: 'POST',
            url: 'http://localhost:8764/pcApi/user/'+ userId,
            dataType: 'json',
            contentType: "application/json",
            success: function (data) {
                $("#username").html(data.username);
                $("#username").attr('href','lw-user.html?userId=' + data.id);
                $("#img").attr('src',data.idPhoto);
                $("#articles").html(data.articles);
                $("#followers").html(data.followers);
                $("#introduction").html(data.introduction);

                console.log(data)
            },
            error: function (XMLHttpRequest, textStatus, errorThown) {
                alert("操作失败！");
            }
        });
    }
    //发表评论
    function pushComment() {
        var currentUserId = localStorage.getItem("userId")
        var text = $("#commentText").val()
        var comment = {"userId":currentUserId,"articleId":articleId,"text":text}

        if(text.length > 0){
            $.ajax({
                type: 'POST',
                url: 'http://localhost:8764/pcApi/comment/create',
                dataType: 'json',
                contentType: "application/json",
                data: JSON.stringify(comment),
                success: function (data) {
                    if(data.errcode === "200"){
                        getComment()
                        layer.msg("发表评论成功")
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThown) {
                    alert("操作失败！");
                }
            });
        }

    }

</script>

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<!--<![endif]-->
<!--[if lte IE 8 ]>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->
<script src="assets/js/amazeui.min.js"></script>
<!-- <script src="assets/js/app.js"></script> -->
</body>
</html>
